//reduce用法数组加和
const arr = [1, 2, 3, 4, 5];
const result = arr.reduce((acc, cur) => {
  return acc + cur;
}, 0);
console.log(result); // 15


//splice用法数组去掉元素并替换
const arr1 = [1, 2, 3, 4, 5];
arr1.splice(1, 2, 6, 7);
console.log(arr1); // [1, 6, 7, 4, 5]

//push用法数组添加元素
const arr2 = [1, 2, 3, 4, 5];
arr2.push(6, 7);
console.log(arr2); // [1, 2, 3, 4, 5, 6, 7]

//foreach用法遍历数组
const arr3 = [1, 2, 3, 4, 5];
arr3.forEach(item => {
  console.log(item); // 1 2 3 4 5
});


//map用法遍历数组并返回新数组
const arr4 = [1, 2, 3, 4, 5];
const newArr = arr4.map(item => {
  return item * 2;
});
console.log(newArr); // [2, 4, 6, 8, 10]

//findIndex用法查找数组元素的索引
const arr5 = [1, 2, 3, 4, 5];
const index = arr5.findIndex(item => {
  return item === 3;
});
console.log(index); // 2

